<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //【1】[[Configurable]]：该特性表示是否可以通过delete操作符来删除属性，默认值是true。
        var obj = {};
        obj.name = "myname";

        delete obj.name;
        console.log(obj.name); //undefined
        //我们通过Object.defineProperty方法来修改[[Configurable]]特性。
        //通过将configurable特性设置成false之后，delete就无法删除name属性了
        var obj = {};
        obj.name = "myname";
        Object.defineProperty(obj, "name", {
            configurable: false
        })

        delete obj.name;
        console.log(obj.name); //myname
        // 【2】[[Enumerable]]：表示是否能够通过for…in语句来枚举出属性，默认是true
        var obj = {
            name: "objName"
        }
        for (var i in obj) {
            console.log(i); //name
        }
        //这段代码只输出了name属性，我们来将constructor属性的[[Enumerable]]设置为true试试。
        var obj = {
            name: "objName"
        }
        Object.defineProperty(obj, "constructor", {
            enumerable: true
        })

        for (var i in obj) {
            console.log(i); //name,constructor
        }
        console.log(obj.propertyIsEnumerable("constructor")); //true
        // 【3】[[writable]]：表示属性值是否可以修改，默认为true
        // 如果[[Writable]]被设置成false，尝试修改时将没有效果，在严格模式下会报错
        var obj_sky = {
            name: "junwei"
        }
        Object.defineProperty(obj_sky, 'name', {
            writable: false
        })
        obj_sky.name = "moon";
        console.log(obj_sky); //
        // 【4】[[value]]：表示属性的值，默认为undefined
        var obj = {
            name: "name"
        };
        console.log(obj.name); //name        

        Object.defineProperty(obj, "name", {
            value: "newValue",
            writable: false
        })
        console.log(obj.name); //newValue

        obj.name = "oldValue";
        console.log(obj.name); //newValue
        // 如果我们通过defineProperty来修改name属性的值，是否可以修改呢？答案是可以的：
        Object.defineProperty(obj, "name", {
            value: "oldValue"
        })
        console.log(obj.name); //oldValue
    </script>
</body>

</html>